package com.gzy.android_douban.ui;

import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.view.MenuItem;
import androidx.annotation.NonNull;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.gzy.android_douban.R;
import com.gzy.android_douban.databinding.ActivityMainBinding;
import com.gzy.android_douban.ui.classify.ClassifyFragment;
import com.gzy.android_douban.ui.home.HomeFragment;
import com.gzy.android_douban.ui.me.MeFragment;

public class MainActivity extends BaseActivity<ActivityMainBinding> {
  ActivityMainBinding binding;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    if (savedInstanceState == null) {
      getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, new HomeFragment()).commit();
    }

    initviewpager();
    initClick();
  }

  // 点击事件
  private void initClick() {

  }

  private void initviewpager() {
    //获取底部导航图标颜色，根据图标颜色设置文字颜色
    Resources resource = getResources();
    @SuppressLint("ResourceType")
    ColorStateList csl = resource.getColorStateList(R.drawable.bottom_navigation_item_selector);

    binding.bottomNavigationView.setItemTextColor(csl);

    binding.bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        Fragment fragment = null;
        switch (item.getItemId()) {
          case R.id.navigation1:
            fragment = new HomeFragment();
            break;
           case R.id.navigation2:
             fragment= new ClassifyFragment();
             break;
          case R.id.navigation3:
            fragment = new MeFragment();
            break;
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout, fragment).commit();
        return true;
      }
    });
  }
}